#include <iostream>
using namespace std;

/*
    this指针
        概念：C++中，类中的成员函数，都有this指针，this指针，指向当前对象
        this指针不需要程序定义
        实现原理：
            Cat *this = &当前对象;
            当前对象-->代码调用的对象
        使用:
            this->成员变量
            (*this).成员变量
*/

class Cat
{
public:
    void catchMouse()
    {
        cout << "this: " << this;
        cout << " 猫抓老鼠" << endl;
    }
    Cat compareAge(Cat c1 , Cat c2)
    {
        if (c1.age > c2.age)
        {
            cout << "c1: " << c1.age << endl;
            cout << "c1: " << this << endl;
            return c1;
        }else
        {
            cout << "c2: " << c2.age << endl;
            // cout << "c2: " << this << endl;
            cout << "c2: " << &c2 << endl;
            return c2;
        }
    }
    Cat compareAge(Cat &other)
    {
        if (this->age >= other.age)
        {
            cout << "this: " << this << endl;
            return *this;
        }else{
            cout << "other: " << &other << endl;
            return other;
        }
    }
    void setAttr(int a)
    {
        this->age = a;
    }
private:
    int age;
};


int main()
{
    Cat c1, c2, c3;
    c1.setAttr(10);
    c2.setAttr(20);
    c1.catchMouse();
    c2.catchMouse();
    cout << "c1: " << &c1 << endl;
    cout << "c2: " << &c2 << endl;
    // 比较年龄
    // c1.compareAge(c1, c2);
    c1.compareAge(c2);

    return 0;
}